//
//  HandSignViewController.m
//  zealcomm4.1Demo
//
//  Created by zealcomm user on 2020/1/10.
//  Copyright © 2020 zealcomm user. All rights reserved.
//

#import "HandSignViewController.h"

@interface HandSignViewController ()

@end

@implementation HandSignViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self.signView initDrawingView];
    self.signView.layer.borderWidth = 1;
    self.signView.layer.borderColor = [UIColor lightGrayColor].CGColor;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

-(void)viewWillDisappear:(BOOL)animated{
    [self sendMessageConfirmation];
}

-(void)sendMessageConfirmation{
    [self.ivcsSdk sendMessageConfirmation:@{
        @"answer":@"ok",
        @"type":@"link",
        @"data":@{
                 @"url": @"https://zealcomm-agentz.oss-cn-shanghai.aliyuncs.com/agentz/bcc133d37ff453506a46e98002a6d181.png?OSSAccessKeyId=LTAIQtmAtbF7Z52f&Expires=16105252911800&Signature=cy0YuUDSz%2BdSqevHsZUO93q09EU%3D",
                 @"urlKey": @"",
                 @"type": @"pic",
                 @"name": @"test.png"
        }
    } toRoles:@"agents" onSuccess:^{
        NSLog(@"sendMessageConfirmation success");
    } onFailure:^(NSError * _Nonnull error) {
        NSLog(@"sendMessageConfirmation failed,%@",error);
    }];
}

- (IBAction)singBack:(id)sender {
    [self.signView doBack];
}

- (IBAction)signUp:(id)sender {
    [self.signView doForward];
}

- (IBAction)send:(id)sender {
    [self.signView saveImage:^(UIImage * _Nonnull image) {
        NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
        [self.ivcsSdk shareResourceWithType:@"pic" uploadUrl:@"https://ivcs-demo.zealcomm.cn:3094/v1/upload" fileData:imageData fileName:@"handwrite.png" mimeType:@"image/png" toRoles:@"agents" onSuccess:^{
            NSLog(@"11success");
        } onFailure:^(NSError * _Nonnull error) {
            NSLog(@"xxx,,%@error",error);
        }];
    }];
    [self sendMessageConfirmation];
    [self.navigationController popViewControllerAnimated:false];
}

-(NSDictionary*)returnDictionaryWithDataPath:(NSData*)data
{
    NSString *receiveStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
    
    NSData * datas = [receiveStr dataUsingEncoding:NSUTF8StringEncoding];
    
    NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:datas options:NSJSONReadingMutableLeaves error:nil];
    
    return jsonDict;
}


@end
